package com.lyz.dataStructure.LeetCode.dongtaiguihua;


/*
将等差数列分段，返回子等差数列的个数包含本身   leetcode 413
 */
public class Solution5 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7};
        System.out.println(number(arr));
    }

    public  static  int number(int[] arr){
        if(arr==null||arr.length==0){
            return 0;
        }

        int n =arr.length;
        int[] dp =new int[n];
        int sum =0;
        for(int i =2;i<n;i++){
            if(arr[i]-arr[i-1]==arr[i-1]-arr[i-2]){
                dp[i] = dp[i-1]+1;
                sum +=dp[i];
            }
        }
        return  sum;
    }
}
